class ReportController < ApplicationController
	layout "main"
  before_filter :admin?, :except=>[:userlogsession, :userlog2]
#  after_filter :post_log, :except=>[:index]

  def users_certified
    if params[:sdate]
      @bdate= Date.new params[:sdate]['bdate(1i)'].to_i,params[:sdate]['bdate(2i)'].to_i,params[:sdate]['bdate(3i)'].to_i
      @edate= Date.new params[:sdate]['edate(1i)'].to_i,params[:sdate]['edate(2i)'].to_i,params[:sdate]['edate(3i)'].to_i
      @users= User.graduated.all :conditions=>
        ['graduation_on>=? AND graduation_on<=?',@bdate,@edate]
    else
      @bdate= Date.today
      @edate= Date.today
      @users= User.graduated.all :conditions=>
        ['graduation_on = ?',@bdate]
    end
  end
  def print_certified
    if params[:sdate]
      @bdate= Date.new params[:sdate]['bdate(1i)'].to_i,params[:sdate]['bdate(2i)'].to_i,params[:sdate]['bdate(3i)'].to_i
      @edate= Date.new params[:sdate]['edate(1i)'].to_i,params[:sdate]['edate(2i)'].to_i,params[:sdate]['edate(3i)'].to_i
      @users= User.graduated.all :conditions=>
        ['graduation_on>=? AND graduation_on<=?',@bdate,@edate]
    else
      @bdate= Date.today
      @edate= Date.today
      @users= User.graduated.all :conditions=>
        ['graduation_on = ?',@bdate]
    end
    render :template=>'report/print_certified53', :layout => false
  end
  def users_certified53
    @users= User.certified53
  end
  def print_certified53
    @users= User.certified53
    render :layout => false
  end
  def exam
    @exam_results= ExamResult.paginate :per_page => "30", :page=>params[:page], :order=>'created_at DESC'
  end
  def exam_overview
    @courses= Course.all
  end
	def chat
    admin?
    params[:page]= 1 if params[:page].blank?
    if params[:login].blank?
      @chats= Chat.paginate :page=>params[:page], :per_page=>30, :order=>"created_at DESC"
    else
      @user= User.find_by_login params[:login]
      @chats= @user.chats.paginate :page=>params[:page], :per_page=>30, :order=>"created_at DESC"
    end
	end

	def singleSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)
		word = get_UTF8_BOM
    word += "<?xml version='1.0' encoding='UTF-8'?>"
		word = word + "<chart palette='"+palette+"' caption='"+caption+"' subcaption='"+subcaption+"' xAxisName='"+xAxisName+"' yAxisName='"+yAxisName+"' showValues='"+showValue+"' numberPrefix='"+numberPrefix+"' formatNumberScale='"+formatNumberScale+"'>"
		count = 0
		label.each do |l|
			word += "<set label='"+l+"' value='"+value[count]+"' link='"+link[count]+"' />"
			count += 1
		end
		
		word += "<trendLines>"
		count3 = 0
		trendlineStartValue.each do |t|
			word += "<line startValue='"+t+"' showOnTop='1' color='"+trendlineColor[count3]+"' displayvalue='"+trendlineDisplayValue[count3]+"' />" 
			count3 += 1
		end
		word += "</trendLines>"
		
#		word += "<styles>"
#		word += "<definition>"
#		word += "<style name='myCaptionFont' type='font' font='AngsanaUPC' size='14' color='666666' bold='1' underline='1'/>"
#		word += "<style name='myShadow' type='Shadow' color='999999' angle='45'/>"
#		word += "<style name='myGlow' type='Glow' color='FF5904'/>"
#		word += "</definition>"
#		word += "<application>"
#		word += "<apply toObject='Caption' styles='myCaptionFont,myShadow' />"
#		word += "<apply toObject='SubCaption' styles='myShadow' />"
#		word += "<apply toObject='XAxisName' styles='myGlow' />"
#		word += "<apply toObject='YAxisName' styles='myGlow' />"
#		word += "</application>"
#		word += "</styles>"
		
		word += "</chart>"
		return word
	end

	def multiSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, seriesName, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)
		word = get_UTF8_BOM
    word += "<?xml version='1.0' encoding='UTF-8'?>"
		word = word + "<chart palette='"+palette+"' caption='"+caption+"' subcaption='"+subcaption+"' xAxisName='"+xAxisName+"' yAxisName='"+yAxisName+"' showValues='"+showValue+"' numberPrefix='"+numberPrefix+"' formatNumberScale='"+formatNumberScale+"'>"
		word += "<categories>"
		label.each do |l|
			word += "<category label='"+l+"' />"		
		end
		word += "</categories>"
		count = 0
		seriesName.each do |s|
			word += "<dataset seriesName='"+s+"'>"
			count2 = 0
			value[count].each do |v|
				word += "<set value='"+v+"' link='"+link[count][count2]+"' />"
				count2 +=1
			end
			word += "</dataset>"
			count += 1
		end
		
		word += "<trendLines>"
		count3 = 0
		trendlineStartValue.each do |t|
			word += "<line startValue='"+t+"' showOnTop='1' color='"+trendlineColor[count3]+"' displayvalue='"+trendlineDisplayValue[count3]+"' />" 
			count3 += 1
		end
		word += "</trendLines>"

		word += "</chart>"
		return word
	end

	def testsingleseries
		palette = '2'
		caption = 'ทดสอบ'
		subcaption = 'การใส่ค่าภาษาไทย'
		xAxisName = 'ปริมาณ'
		yAxisName = 'ราคา'
		showValue = '0'
		numberPrefix = ''
		formatNumberScale = '0'
		width = '800'
		height = '400'
		label = ['10','20','30']
		value = ['40','20','5']
		link = ['','',CGI.escape('http://www.google.co.th')]
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = singleSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
		headers["Content-Type"] = "application/xml"
		render :text=> unicode2ascii(word)
	end

	def testmultiseries
		palette = '2'
		caption = 'ทดสอบ'
		subcaption = 'การใส่ค่าภาษาไทย'
		xAxisName = 'ปริมาณ'
		yAxisName = 'ราคา'
		showValue = '0'
		numberPrefix = ''
		formatNumberScale = '0'
		width = '800'
		height = '400'
		seriesName = ['2007','2008']
		label = ['10','20','30']
		value = ['40','20','5'],['82','70','90']
		link = ['','',CGI.escape('http://www.google.co.th')],['',CGI.escape('http://www.yahoo.com'),'']
		trendlineStartValue = ['32','80']
		trendlineColor = ['ffff00','00ff00']
		trendlineDisplayValue = ['Warning','Target']
		word = multiSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, seriesName, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
		headers["Content-Type"] = "application/xml"
		render :text=> unicode2ascii(word)
#		render :text=> word
	end

	def showsingleseries
		@width = '600'
		@height = '400'
		@gtype = 'Line'

		# Column2D, Column3D, Pie2D, Pie3D, Area2D, Area3D, Line
	end

	def showmultiseries
		@width = '600'
		@height = '400'
		@gtype = 'MSLine'

		# MSArea, MSBar2D, MSColumn2D, MSColumn3D, MSLine
	end

	def unicode2ascii(str)
		converted = []
		str.unpack("U*").collect {|s| converted << ((s >= 3585 && s <= 3675) ? (s - 3424).chr : ((s > 3675) ? " " : s.chr))}
		converted.join('')
	end

	def showallcourses
		if params[:id]!=nil
			session[:signed_user_id] = params[:id]
		else
			session[:signed_user_id] = nil
		end
		@width = '600'
		@height = '400'
		@gtype = 'Pie2D'
	end

	def showalldiscussions
		if params[:id]!=nil
			session[:signed_user_id] = params[:id]
		else
			session[:signed_user_id] = nil
		end
		@width = '600'
		@height = '500'
		@gtype = 'Pie2D'
	end

	def showtableallcourses
		@courses = Course.find:all
	end

	def showcourse
		@id = params[:id]
		@width = '600'
		@height = '400'
		@gtype = 'MSLine'
	end

	def showdiscussion
		@id = params[:id]
		@width = '600'
		@height = '400'
		@gtype = 'MSLine'
	end

	def showdailycourse
		@id = params[:id]
		@month = params[:month]
		session[:month] = params[:month]	
		@width = '600'
		@height = '400'
		@gtype = 'MSLine'
	end

	def showdailydiscussion
		@id = params[:id]
		@month = params[:month]
		session[:month] = params[:month]	
		@width = '600'
		@height = '400'
		@gtype = 'MSLine'
	end

	def showallviews
		if params[:id]!=nil
			session[:signed_user_id] = params[:id]
		else
			session[:signed_user_id] = nil
		end
		@width = '600'
		@height = '400'
		@gtype = 'Column3D'
	end
  def users_province
    @provinces= User.all :select=>'DISTINCT province', :order=>"province"
  end
  def users_amphoe
    if params[:province]=~ /\d+/
      @province_name=Province.find_by_code(params[:province]).th
    else
      @province_name=params[:province]
    end
    @amphoes= User.all :select=>'DISTINCT amphoe', :order=>"amphoe", :conditions=>["province=?",params[:province]]
  end
  def users_tambon
    @users= User.all :conditions=>["province=? and amphoe=?",params[:province], params[:amphoe]], :order=>"login"
    if params[:province]=~ /\d{2}/
      @province_name=Province.find_by_code(params[:province]).th
    else
      @province_name=params[:province]
    end
    if params[:amphoe]=~ /\d{4}/
      @amphoe_name=Amphoe.find_by_code(params[:amphoe]).th
    else
      @amphoe_name=params[:amphoe]
    end
  end
  def newsletter
    @newsletters= Log.paginate :page=>params[:page], :per_page=>30, :conditions=>"action='send_mail_to_group_by_course'", :order=>"created_at DESC"
  end
  def pre_requisite
    @exams= Exam.all
  end
  def exam_create
    @logs= Log.paginate :page=>params[:page], :per_page=>30, :conditions=>"controller='exam' AND action='create'", :order=>"created_at DESC"
  end
  def blog
		@width = '600'
		@height = '400'
		@gtype = 'Column3D'
  end
	def blog_data
		year = (Date.today).year
		palette = '3'
		caption = "กราฟแสดงการใช้งานบล็อกประจำปี พ.ศ. #{year+543}"
		subcaption = ''
		xAxisName = ''
		yAxisName = ''
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
		label = ['ม.ค.', 'ก.พ.', 'มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.']
#		label = ['มกราคม', 'กุมภาพันธ์', 'มีนาคม','เมษายน','พฤษาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม']
		value = Array.new

		m1 = Log.count(:all, :conditions=>["controller='blog' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-01-31"])
		m3 = Log.count(:all, :conditions=>["controller='blog' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-03-31"])
		m4 = Log.count(:all, :conditions=>["controller='blog' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-04-30"])
		m5 = Log.count(:all, :conditions=>["controller='blog' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-05-31"])
		m6 = Log.count(:all, :conditions=>["controller='blog' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-06-30"])
		m7 = Log.count(:all, :conditions=>["controller='blog' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-07-31"])
		m8 = Log.count(:all, :conditions=>["controller='blog' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-08-31"])
		m9 = Log.count(:all, :conditions=>["controller='blog' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-09-30"])
		m10 = Log.count(:all, :conditions=>["controller='blog' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-10-31"])
		m11 = Log.count(:all, :conditions=>["controller='blog' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-11-30"])
		m12 = Log.count(:all, :conditions=>["controller='blog' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-12-31"])

		value = value << m1.to_s
		if year%4 ==0
			m2 = Log.count(:all, :conditions=>["controller='blog' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-02-29"])
			value = value << m2.to_s
		else
			m2 = Log.count(:all, :conditions=>["controller='blog' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-02-28"])
			value = value << m2.to_s
		end
		value = value << m3.to_s
		value = value << m4.to_s
		value = value << m5.to_s
		value = value << m6.to_s
		value = value << m7.to_s
		value = value << m8.to_s
		value = value << m9.to_s
		value = value << m10.to_s
		value = value << m11.to_s
		value = value << m12.to_s

		link = ['','','','','','','','','','','','']
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = singleSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end
  def video_stream
		@width = '600'
		@height = '400'
		@gtype = 'Column3D'
  end
	def video_stream_data
		year = (Date.today).year
		palette = '3'
		caption = 'กราฟแสดงการใช้งานวิดีทัศน์สดประจำปี พ.ศ. '+(year+543).to_s
		subcaption = ''
		xAxisName = ''
		yAxisName = ''
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
		label = ['ม.ค.', 'ก.พ.', 'มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.']
#		label = ['มกราคม', 'กุมภาพันธ์', 'มีนาคม','เมษายน','พฤษาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม']
		value = Array.new

		m1 = Log.count(:all, :conditions=>["action='video_stream' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-01-31"])
		m3 = Log.count(:all, :conditions=>["action='video_stream' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-03-31"])
		m4 = Log.count(:all, :conditions=>["action='video_stream' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-04-30"])
		m5 = Log.count(:all, :conditions=>["action='video_stream' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-05-31"])
		m6 = Log.count(:all, :conditions=>["action='video_stream' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-06-30"])
		m7 = Log.count(:all, :conditions=>["action='video_stream' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-07-31"])
		m8 = Log.count(:all, :conditions=>["action='video_stream' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-08-31"])
		m9 = Log.count(:all, :conditions=>["action='video_stream' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-09-30"])
		m10 = Log.count(:all, :conditions=>["action='video_stream' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-10-31"])
		m11 = Log.count(:all, :conditions=>["action='video_stream' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-11-30"])
		m12 = Log.count(:all, :conditions=>["action='video_stream' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-12-31"])

		value = value << m1.to_s
		if year%4 ==0
			m2 = Log.count(:all, :conditions=>["action='video_stream' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-02-29"])
			value = value << m2.to_s
		else
			m2 = Log.count(:all, :conditions=>["action='video_stream' AND created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-02-28"])
			value = value << m2.to_s
		end
		value = value << m3.to_s
		value = value << m4.to_s
		value = value << m5.to_s
		value = value << m6.to_s
		value = value << m7.to_s
		value = value << m8.to_s
		value = value << m9.to_s
		value = value << m10.to_s
		value = value << m11.to_s
		value = value << m12.to_s

		link = ['','','','','','','','','','','','']
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = singleSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end
	def video_stream_course_data
    year= Time.now.year
    dstart= Time.local year,1,1
    dend= Time.local year,12,31,23,59,59
		palette = '3'
		caption = "การใช้งานวิดีทัศน์สดแยกตามหลักสูตร"
		subcaption = ''
		xAxisName = ''
		yAxisName = 'account'
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
    label= Course.all.collect {|c| c.name}
		value = Array.new
    d=[0,0,0,0,0,0]
    Log.all( :conditions=>["action='video_stream' AND created_at>=? AND created_at<=?", dstart, dend]).each do |l|
      video= Video.find l.params[:id]
      d[video.course.id] += 1
    end

		value = value << d[1].to_s
		value = value << d[2].to_s
		value = value << d[3].to_s
		value = value << d[4].to_s
		value = value << d[5].to_s

		link = ['','','','','']
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = singleSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end


	def showallusers
		@width = '600'
		@height = '400'
		@gtype = 'Column3D'
	end

	def showallusers_gender_selectdate
		year = Date.today.year
		@log1 = Log.new
		@log1.created_at = DateTime.parse(year.to_s+'-01-01 00:00 AM')
		@log2 = Log.new
		@log2.created_at = DateTime.parse(year.to_s+'-12-31 11:59 PM')
	end

	def showallusers_education_selectdate
		year = Date.today.year
		@log1 = Log.new
		@log1.created_at = DateTime.parse(year.to_s+'-01-01 00:00 AM')
		@log2 = Log.new
		@log2.created_at = DateTime.parse(year.to_s+'-12-31 11:59 PM')
	end

	def showallusers_role_selectdate
		year = Date.today.year
		@log1 = Log.new
		@log1.created_at = DateTime.parse(year.to_s+'-01-01 00:00 AM')
		@log2 = Log.new
		@log2.created_at = DateTime.parse(year.to_s+'-12-31 11:59 PM')
	end

	def showtablealllogins_selectdate
		year = Date.today.year
		@log1 = Log.new
		@log1.created_at = DateTime.parse(year.to_s+'-01-01 00:00 AM')
		@log2 = Log.new
		@log2.created_at = DateTime.parse(year.to_s+'-12-31 11:59 PM')
	end

	def showtableallusers_lao_selectdate
		year = Date.today.year
		@log1 = Log.new
		@log1.created_at = DateTime.parse(year.to_s+'-01-01 00:00 AM')
		@log2 = Log.new
		@log2.created_at = DateTime.parse(year.to_s+'-12-31 11:59 PM')
	end

	def showallusers_gender
		session[:report_startdate] = params[:log1][:created_at]
		session[:report_enddate] = params[:log2][:created_at]
		@width = '600'
		@height = '500'
		@gtype = 'Pie2D'
	end

	def showallusers_education
		session[:report_startdate] = params[:log1][:created_at]
		session[:report_enddate] = params[:log2][:created_at]
		@width = '600'
		@height = '500'
		@gtype = 'Pie2D'
	end

	def showallusers_role
		session[:report_startdate] = params[:log1][:created_at]
		session[:report_enddate] = params[:log2][:created_at]
		@width = '600'
		@height = '500'
		@gtype = 'Pie2D'
	end

	def showtableallusers_lao
		if params[:log1]
			session[:report_startdate] = params[:log1][:created_at]
		end
		if params[:log2]
			session[:report_enddate] = params[:log2][:created_at]
		end
		@laos = Lao.paginate(:all, :page => params[:page], :per_page => 100, :order=>"code")
	end

	def preshowtablealllogins
		session[:report_startdate] = params[:log1][:created_at]
		session[:report_enddate] = params[:log2][:created_at]
		redirect_to :action=>"showtablealllogins"
	end

	def showtablealllogins
		@logs = Log.paginate(:conditions =>["action = ? AND created_at >= ? AND created_at <= ?" , 'authenticate', session[:report_startdate], session[:report_enddate]] , :page => params[:page], :per_page => 100, :order=>'created_at DESC')
		#login_tcid
	end

	def showyearviews
		@width = '600'
		@height = '400'
		@year = params[:id]
		@gtype = 'Line'
	end

	def allcoursesdata
		palette = '2'
		year = (Date.today).year
		caption = 'แผนภูมิวงกลมแสดงปริมาณการดาวน์โหลด แยกรายวิชา'
		subcaption = 'ประจำปี '+(year+543).to_s
		xAxisName = ''
		yAxisName = ''
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
		label = Array.new
		value = Array.new
		link = Array.new
		courses = Course.find:all
		sql_user_word = ' '
		if session[:signed_user_id] != nil
			sql_user_word = ' user_id='+session[:signed_user_id]+' and '
		end
		courses.each do |c|
			totalDownload = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+c.id.to_s+" and created_at>='"+year.to_s+"-01-01' and created_at<='"+year.to_s+"-12-31'"
			label = label << c.name
			value = value << totalDownload.to_s
			link = link << CGI.escape('/report/showcourse/'+c.id.to_s)
		end
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = singleSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end

	def alldiscussionsdata
		palette = '2'
		year = (Date.today).year
		caption = 'แผนภูมิวงกลมแสดงปริมาณการตั้งกระทู้ แยกตาม Forum'
		subcaption = 'ประจำปี '+(year+543).to_s
		xAxisName = ''
		yAxisName = ''
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
		label = Array.new
		value = Array.new
		link = Array.new
		testword = ''
		sql = ''
		sql_user_word = ' '
		if session[:signed_user_id] != nil
			sql_user_word = ' user_id='+session[:signed_user_id]+' and '
		end
		forums = Forum.find(:all, :conditions => {:status_flag => 'Y'})
		forums.each do |f|
			acount = nil
			if session[:signed_user_id]
				account = User.find(session[:signed_user_id])
				c =  Topic.count(:all, :conditions => ["forum_id=? AND create_by=? AND status_flag=? AND create_on>=? AND create_on<=?", f.id,account.login,'Y',"#{year}-01-01","#{year}-12-31"])
			else
				c =  Topic.count(:all, :conditions => ["forum_id=? AND status_flag=? AND create_on>=? AND create_on<=?", f.id,'Y',"#{year}-01-01","#{year}-12-31"])
			end
			label = label << f.forum_name
			value = value << c.to_s
			link = link << CGI.escape('/report/showdiscussion/'+f.id.to_s)
		end
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = singleSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end

	def allviewsdata
		palette = '2'
		year = (Date.today).year
		caption = 'แผนแสดงอัตราการเข้าชม Web-site'
		subcaption = 'ประจำปี '+(year+543).to_s
		xAxisName = ''
		yAxisName = ''
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
		label = Array.new
		value = Array.new
		link = Array.new
		testword = ''
		sql = ''

		sql_user_word = ' '
		if session[:signed_user_id] != nil
			sql_user_word = ' user_id='+session[:signed_user_id]+' and '
		end
		sql = "select count(distinct(session_id)) from logs where"+sql_user_word+"created_at>='"+year.to_s+"-01-01' and created_at<='"+year.to_s+"-12-31'"
		yearviews = Log.count_by_sql sql
	
		sql = "select count(distinct(session_id)) from logs where"+sql_user_word+"created_at<='"+year.to_s+"-12-31'"
		allviews = Log.count_by_sql sql
		
		label = label << (year+543).to_s
		label = label << 'รวมทุกปี'
		
		value = value << yearviews.to_s
		value = value << allviews.to_s

		link = link << CGI.escape('/report/showyearviews/'+year.to_s)
		link = link << ''

		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = singleSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end

	def coursedata
		course = Course.find(params[:id])
		year = (Date.today).year
		palette = '3'
		caption = 'กราฟแสดงปริมาณการดาวน์โหลดวิชา '+course.name+' ประจำปี '+(year+543).to_s
		subcaption = '(ปริมาณ(ครั้ง) , ปริมาณสะสม)'
		xAxisName = ''
		yAxisName = 'ครั้ง'
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
		seriesName = ['ปริมาณ(ครั้ง)','ปริมาณสะสม']
		label = ['มกราคม', 'กุมภาพันธ์', 'มีนาคม','เมษายน','พฤษาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม']		
		value1 = Array.new
		sql_user_word = ' '
		if session[:signed_user_id] != nil
			sql_user_word = ' user_id='+session[:signed_user_id]+' and '
		end
		m1 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-01-01' and created_at<='"+year.to_s+"-01-31'"
		m3 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-03-01' and created_at<='"+year.to_s+"-03-31'"
		m4 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-04-01' and created_at<='"+year.to_s+"-04-30'"
		m5 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-05-01' and created_at<='"+year.to_s+"-05-31'"
		m6 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-06-01' and created_at<='"+year.to_s+"-06-30'"
		m7 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-07-01' and created_at<='"+year.to_s+"-07-31'"
		m8 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-08-01' and created_at<='"+year.to_s+"-08-31'"
		m9 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-09-01' and created_at<='"+year.to_s+"-09-30'"
		m10 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-10-01' and created_at<='"+year.to_s+"-10-31'"
		m11 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-11-01' and created_at<='"+year.to_s+"-11-30'"
		m12 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-12-01' and created_at<='"+year.to_s+"-12-31'"
		value1 = value1 << m1.to_s
		if year%4 ==0
			m2 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-02-01' and created_at<='"+year.to_s+"-02-29'"
			value1 = value1 << m2.to_s
		else
			m2 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-02-01' and created_at<='"+year.to_s+"-02-28'"
			value1 = value1 << m2.to_s
		end
		value1 = value1 << m3.to_s
		value1 = value1 << m4.to_s
		value1 = value1 << m5.to_s
		value1 = value1 << m6.to_s
		value1 = value1 << m7.to_s
		value1 = value1 << m8.to_s
		value1 = value1 << m9.to_s
		value1 = value1 << m10.to_s
		value1 = value1 << m11.to_s
		value1 = value1 << m12.to_s

		value2 = Array.new
		value2 = value2 << m1.to_s
		value2 = value2 << (m1+m2).to_s
		value2 = value2 << (m1+m2+m3).to_s
		value2 = value2 << (m1+m2+m3+m4).to_s
		value2 = value2 << (m1+m2+m3+m4+m5).to_s
		value2 = value2 << (m1+m2+m3+m4+m5+m6).to_s
		value2 = value2 << (m1+m2+m3+m4+m5+m6+m7).to_s
		value2 = value2 << (m1+m2+m3+m4+m5+m6+m7+m8).to_s
		value2 = value2 << (m1+m2+m3+m4+m5+m6+m7+m8+m9).to_s
		value2 = value2 << (m1+m2+m3+m4+m5+m6+m7+m8+m9+m10).to_s
		value2 = value2 << (m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11).to_s
		value2 = value2 << (m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12).to_s

		value = Array.new
		value = value << value1
		value = value << value2

		link1 = Array.new
		link1 = link1 << CGI.escape('/report/showdailycourse?id='+course.id.to_s+'&month=1')
		link1 = link1 << CGI.escape('/report/showdailycourse?id='+course.id.to_s+'&month=2')
		link1 = link1 << CGI.escape('/report/showdailycourse?id='+course.id.to_s+'&month=3')
		link1 = link1 << CGI.escape('/report/showdailycourse?id='+course.id.to_s+'&month=4')
		link1 = link1 << CGI.escape('/report/showdailycourse?id='+course.id.to_s+'&month=5')
		link1 = link1 << CGI.escape('/report/showdailycourse?id='+course.id.to_s+'&month=6')
		link1 = link1 << CGI.escape('/report/showdailycourse?id='+course.id.to_s+'&month=7')
		link1 = link1 << CGI.escape('/report/showdailycourse?id='+course.id.to_s+'&month=8')
		link1 = link1 << CGI.escape('/report/showdailycourse?id='+course.id.to_s+'&month=9')
		link1 = link1 << CGI.escape('/report/showdailycourse?id='+course.id.to_s+'&month=10')
		link1 = link1 << CGI.escape('/report/showdailycourse?id='+course.id.to_s+'&month=11')
		link1 = link1 << CGI.escape('/report/showdailycourse?id='+course.id.to_s+'&month=12')

		link2 = link1
		
		link = Array.new
		link = link << link1
		link = link << link2
#		link = ['','','','','','','','','','','',''],['','','','','','','','','','','','']
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = multiSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, seriesName, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end

	def yearviewsdata
		year = (Date.today).year
		palette = '3'
		caption = 'กราฟแสดงปริมาณการเข้าชม Web-site ประจำปี '+(year+543).to_s+' จำแนกรายเดือน'
		subcaption = ''
		xAxisName = ''
		yAxisName = 'ครั้ง'
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
		label = ['มกราคม', 'กุมภาพันธ์', 'มีนาคม','เมษายน','พฤษาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม']		
		value = Array.new
		sql_user_word = ' '
		if session[:signed_user_id] != nil
			sql_user_word = ' user_id='+session[:signed_user_id]+' and '
		end
		m1 = Log.count_by_sql "select count(distinct(session_id)) from logs where"+sql_user_word+"created_at>='"+year.to_s+"-01-01' and created_at<='"+year.to_s+"-01-31'"
		m3 = Log.count_by_sql "select count(distinct(session_id)) from logs where"+sql_user_word+"created_at>='"+year.to_s+"-03-01' and created_at<='"+year.to_s+"-03-31'"
		m4 = Log.count_by_sql "select count(distinct(session_id)) from logs where"+sql_user_word+"created_at>='"+year.to_s+"-04-01' and created_at<='"+year.to_s+"-04-30'"
		m5 = Log.count_by_sql "select count(distinct(session_id)) from logs where"+sql_user_word+"created_at>='"+year.to_s+"-05-01' and created_at<='"+year.to_s+"-05-31'"
		m6 = Log.count_by_sql "select count(distinct(session_id)) from logs where"+sql_user_word+"created_at>='"+year.to_s+"-06-01' and created_at<='"+year.to_s+"-06-30'"
		m7 = Log.count_by_sql "select count(distinct(session_id)) from logs where"+sql_user_word+"created_at>='"+year.to_s+"-07-01' and created_at<='"+year.to_s+"-07-31'"
		m8 = Log.count_by_sql "select count(distinct(session_id)) from logs where"+sql_user_word+"created_at>='"+year.to_s+"-08-01' and created_at<='"+year.to_s+"-08-31'"
		m9 = Log.count_by_sql "select count(distinct(session_id)) from logs where"+sql_user_word+"created_at>='"+year.to_s+"-09-01' and created_at<='"+year.to_s+"-09-30'"
		m10 = Log.count_by_sql "select count(distinct(session_id)) from logs where"+sql_user_word+"created_at>='"+year.to_s+"-10-01' and created_at<='"+year.to_s+"-10-31'"
		m11 = Log.count_by_sql "select count(distinct(session_id)) from logs where"+sql_user_word+"created_at>='"+year.to_s+"-11-01' and created_at<='"+year.to_s+"-11-30'"
		m12 = Log.count_by_sql "select count(distinct(session_id)) from logs where"+sql_user_word+"created_at>='"+year.to_s+"-12-01' and created_at<='"+year.to_s+"-12-31'"
		value = value << m1.to_s
		if year%4 ==0
			m2 = Log.count_by_sql "select count(distinct(session_id)) from logs where"+sql_user_word+"created_at>='"+year.to_s+"-02-01' and created_at<='"+year.to_s+"-02-29'"
			value = value << m2.to_s
		else
			m2 = Log.count_by_sql "select count(distinct(session_id)) from logs where"+sql_user_word+"created_at>='"+year.to_s+"-02-01' and created_at<='"+year.to_s+"-02-28'"
			value = value << m2.to_s
		end
		value = value << m3.to_s
		value = value << m4.to_s
		value = value << m5.to_s
		value = value << m6.to_s
		value = value << m7.to_s
		value = value << m8.to_s
		value = value << m9.to_s
		value = value << m10.to_s
		value = value << m11.to_s
		value = value << m12.to_s

		link = ['','','','','','','','','','','','']
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = singleSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end

	def allusersdata
		year = (Date.today).year
		palette = '3'
		caption = 'กราฟแสดงปริมาณสะสมของ user ในระบบ ประจำปี พ.ศ. '+(year+543).to_s
		subcaption = ''
		xAxisName = ''
		yAxisName = 'account'
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
		label = ['มกราคม', 'กุมภาพันธ์', 'มีนาคม','เมษายน','พฤษาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม']		
		value = Array.new

		m1 = User.count(:all, :conditions=>["created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-01-31"])
		m3 = User.count(:all, :conditions=>["created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-03-31"])
		m4 = User.count(:all, :conditions=>["created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-04-30"])
		m5 = User.count(:all, :conditions=>["created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-05-31"])
		m6 = User.count(:all, :conditions=>["created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-06-30"])
		m7 = User.count(:all, :conditions=>["created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-07-31"])
		m8 = User.count(:all, :conditions=>["created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-08-31"])
		m9 = User.count(:all, :conditions=>["created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-09-30"])
		m10 = User.count(:all, :conditions=>["created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-10-31"])
		m11 = User.count(:all, :conditions=>["created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-11-30"])
		m12 = User.count(:all, :conditions=>["created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-12-31"])

		value = value << m1.to_s
		if year%4 ==0
			m2 = User.count(:all, :conditions=>["created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-02-29"])
			value = value << m2.to_s
		else
			m2 = User.count(:all, :conditions=>["created_at>=? AND created_at<=?",  year.to_s+"-01-01", year.to_s+"-02-28"])
			value = value << m2.to_s
		end
		value = value << m3.to_s
		value = value << m4.to_s
		value = value << m5.to_s
		value = value << m6.to_s
		value = value << m7.to_s
		value = value << m8.to_s
		value = value << m9.to_s
		value = value << m10.to_s
		value = value << m11.to_s
		value = value << m12.to_s

		link = ['','','','','','','','','','','','']
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = singleSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end

	def allusersgenderdata
		startdate = session[:report_startdate]
		enddate = session[:report_enddate]
		palette = '3'
		caption = 'กราฟแสดงปริมาณของ user ในระบบ(จำแนกตามเพศ) ระหว่าง '+startdate+' ถึง '+enddate 
		subcaption = ''
		xAxisName = ''
		yAxisName = 'account'
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
		label = ['ชาย', 'หญิง', 'ไม่ระบุ']		
		value = Array.new

		d1 = User.count(:all, :conditions=>["created_at>=? AND created_at<=? AND title = ?",  startdate, enddate, 'นาย'])
		d21 = User.count(:all, :conditions=>["created_at>=? AND created_at<=? AND title = ?",  startdate, enddate, 'นาง'])
		d22 = User.count(:all, :conditions=>["created_at>=? AND created_at<=? AND title = ?",  startdate, enddate, 'นางสาว'])
		d3 = User.count(:all, :conditions=>["created_at>=? AND created_at<=?",  startdate, enddate])
		
		value = value << d1.to_s
		value = value << (d21+d22).to_s
		value = value << (d3-(d1+d21+d22)).to_s

		link = ['','','']
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = singleSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
#		headers["Content-Type"] = "application/xml"
#		render :text unicode2ascii(word)
		response.headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end

	def allusersroledata
		startdate = session[:report_startdate]
		enddate = session[:report_enddate]
		palette = '3'
		caption = 'กราฟแสดงปริมาณของ user ในระบบ(จำแนกตามประเภทผู้ใช้งาน) ระหว่าง '+startdate+' ถึง '+enddate 
		subcaption = ''
		xAxisName = ''
		yAxisName = 'account'
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
		label = Array.new
    value = Array.new
    link = Array.new
    uts = UserType.find(:all, :order=>"id")
    uts.each do |ut|
      label = label << ut.name
      value = value << User.count(:all, :conditions=>["created_at>=? AND created_at<=? AND user_type_id = ?",  startdate, enddate, ut.id]).to_s
      link = link << ''
    end
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = singleSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end

	def alluserseducationdata
		startdate = session[:report_startdate]
		enddate = session[:report_enddate]
		palette = '3'
		caption = 'กราฟแสดงปริมาณของ user ในระบบ(จำแนกตามระดับการศึกษาสูงสุด) ระหว่าง '+startdate+' ถึง '+enddate 
		subcaption = ''
		xAxisName = ''
		yAxisName = 'account'
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
    label = Array.new
    value = Array.new
    link = Array.new
    es = Education.find(:all, :order=>"id")
    es.each do |e|
      label = label << e.name
      value = value << User.count(:all,  :conditions => ["created_at >= ? AND created_at <=? AND education_id = ?", startdate, enddate, e.id]).to_s
      link = link << ''
    end
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = singleSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end

	def filterforum(logs, id)
		c = 0
		logs.each do |l|
			if l.params[:topic][:forum_id]==id.to_s
				c = c+1
			end
		end
		return c
	end

	def discussiondata
		forum = Forum.find(params[:id])
		year = (Date.today).year
		palette = '3'
		caption = 'กราฟแสดงปริมาณการตั้งกระทู้ประจำ Forum '+forum.forum_name+' ประจำปี '+(year+543).to_s
		subcaption = '(ปริมาณ(ครั้ง) , ปริมาณสะสม)'
		xAxisName = ''
		yAxisName = 'ครั้ง'
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
		seriesName = ['ปริมาณ(ครั้ง)','ปริมาณสะสม']
		label = ['มกราคม', 'กุมภาพันธ์', 'มีนาคม','เมษายน','พฤษาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม']		
		value1 = Array.new
		sql_user_word = ' '
		if session[:signed_user_id] != nil
			sql_user_word = ' user_id='+session[:signed_user_id]+' and '
		end
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-01-01' and created_at<='"+year.to_s+"-01-31'"
		m1 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-03-01' and created_at<='"+year.to_s+"-03-31'"
		m3 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-04-01' and created_at<='"+year.to_s+"-04-30'"
		m4 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-05-01' and created_at<='"+year.to_s+"-05-31'"
		m5 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-06-01' and created_at<='"+year.to_s+"-06-30'"
		m6 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-07-01' and created_at<='"+year.to_s+"-07-31'"
		m7 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-08-01' and created_at<='"+year.to_s+"-08-31'"
		m8 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-09-01' and created_at<='"+year.to_s+"-09-30'"
		m9 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-10-01' and created_at<='"+year.to_s+"-10-31'"
		m10 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-11-01' and created_at<='"+year.to_s+"-11-30'"
		m11 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-12-01' and created_at<='"+year.to_s+"-12-31'"
		m12 = filterforum(logs, forum.id)
		value1 = value1 << m1.to_s
		if year%4 ==0
			logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-02-01' and created_at<='"+year.to_s+"-02-29'"
			m2 = filterforum(logs, forum.id)
			value1 = value1 << m2.to_s
		else
			logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-02-01' and created_at<='"+year.to_s+"-02-28'"
			m2 = filterforum(logs, forum.id)
			value1 = value1 << m2.to_s
		end
		value1 = value1 << m3.to_s
		value1 = value1 << m4.to_s
		value1 = value1 << m5.to_s
		value1 = value1 << m6.to_s
		value1 = value1 << m7.to_s
		value1 = value1 << m8.to_s
		value1 = value1 << m9.to_s
		value1 = value1 << m10.to_s
		value1 = value1 << m11.to_s
		value1 = value1 << m12.to_s

		value2 = Array.new
		value2 = value2 << m1.to_s
		value2 = value2 << (m1+m2).to_s
		value2 = value2 << (m1+m2+m3).to_s
		value2 = value2 << (m1+m2+m3+m4).to_s
		value2 = value2 << (m1+m2+m3+m4+m5).to_s
		value2 = value2 << (m1+m2+m3+m4+m5+m6).to_s
		value2 = value2 << (m1+m2+m3+m4+m5+m6+m7).to_s
		value2 = value2 << (m1+m2+m3+m4+m5+m6+m7+m8).to_s
		value2 = value2 << (m1+m2+m3+m4+m5+m6+m7+m8+m9).to_s
		value2 = value2 << (m1+m2+m3+m4+m5+m6+m7+m8+m9+m10).to_s
		value2 = value2 << (m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11).to_s
		value2 = value2 << (m1+m2+m3+m4+m5+m6+m7+m8+m9+m10+m11+m12).to_s

		value = Array.new
		value = value << value1
		value = value << value2

		link1 = Array.new
		link1 = link1 << CGI.escape('/report/showdailydiscussion?id='+forum.id.to_s+'&month=1')
		link1 = link1 << CGI.escape('/report/showdailydiscussion?id='+forum.id.to_s+'&month=2')
		link1 = link1 << CGI.escape('/report/showdailydiscussion?id='+forum.id.to_s+'&month=3')
		link1 = link1 << CGI.escape('/report/showdailydiscussion?id='+forum.id.to_s+'&month=4')
		link1 = link1 << CGI.escape('/report/showdailydiscussion?id='+forum.id.to_s+'&month=5')
		link1 = link1 << CGI.escape('/report/showdailydiscussion?id='+forum.id.to_s+'&month=6')
		link1 = link1 << CGI.escape('/report/showdailydiscussion?id='+forum.id.to_s+'&month=7')
		link1 = link1 << CGI.escape('/report/showdailydiscussion?id='+forum.id.to_s+'&month=8')
		link1 = link1 << CGI.escape('/report/showdailydiscussion?id='+forum.id.to_s+'&month=9')
		link1 = link1 << CGI.escape('/report/showdailydiscussion?id='+forum.id.to_s+'&month=10')
		link1 = link1 << CGI.escape('/report/showdailydiscussion?id='+forum.id.to_s+'&month=11')
		link1 = link1 << CGI.escape('/report/showdailydiscussion?id='+forum.id.to_s+'&month=12')

		link2 = link1
		
		link = Array.new
		link = link << link1
		link = link << link2
#		link = ['','','','','','','','','','','',''],['','','','','','','','','','','','']
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = multiSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, seriesName, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end

	def dailycoursedata
		course = Course.find(params[:id])
		pmonth = session[:month]
		month = pmonth.to_i
#		course = Course.find(1)
#		month = 10
		
		monthword = ['มกราคม', 'กุมภาพันธ์', 'มีนาคม','เมษายน','พฤษาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม']
		year = (Date.today).year
		palette = '3'
		caption = 'กราฟแสดงปริมาณการดาวน์โหลดวิชา '+course.name+' ประจำเดือน '+monthword[month-1]+' ปี '+(year+543).to_s
		subcaption = '(ปริมาณ(ครั้ง) , ปริมาณสะสม)'
		xAxisName = ''
		yAxisName = 'ครั้ง'
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
		seriesName = ['ปริมาณ(ครั้ง)','ปริมาณสะสม']
		label = ['1', '2', '3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31']
		
		m = ''
		if month<10
			m = '0'+month.to_s
		else
			m = month.to_s
		end
		sql_user_word = ' '
		if session[:signed_user_id] != nil
			sql_user_word = ' user_id='+session[:signed_user_id]+' and '
		end
		d1 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-01 00:00:00' and created_at<='"+year.to_s+"-"+m+"-01 23:59:59'"
		d2 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-02 00:00:00' and created_at<='"+year.to_s+"-"+m+"-02 23:59:59'"
		d3 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-03 00:00:00' and created_at<='"+year.to_s+"-"+m+"-03 23:59:59'"
		d4 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-04 00:00:00' and created_at<='"+year.to_s+"-"+m+"-04 23:59:59'"
		d5 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-05 00:00:00' and created_at<='"+year.to_s+"-"+m+"-05 23:59:59'"
		d6 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-06 00:00:00' and created_at<='"+year.to_s+"-"+m+"-06 23:59:59'"
		d7 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-07 00:00:00' and created_at<='"+year.to_s+"-"+m+"-07 23:59:59'"
		d8 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-08 00:00:00' and created_at<='"+year.to_s+"-"+m+"-08 23:59:59'"
		d9 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-09 00:00:00' and created_at<='"+year.to_s+"-"+m+"-09 23:59:59'"
		d10 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-10 00:00:00' and created_at<='"+year.to_s+"-"+m+"-10 23:59:59'"
		d11 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-11 00:00:00' and created_at<='"+year.to_s+"-"+m+"-11 23:59:59'"
		d12 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-12 00:00:00' and created_at<='"+year.to_s+"-"+m+"-12 23:59:59'"
		d13 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-13 00:00:00' and created_at<='"+year.to_s+"-"+m+"-13 23:59:59'"
		d14 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-14 00:00:00' and created_at<='"+year.to_s+"-"+m+"-14 23:59:59'"
		d15 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-15 00:00:00' and created_at<='"+year.to_s+"-"+m+"-15 23:59:59'"
		d16 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-16 00:00:00' and created_at<='"+year.to_s+"-"+m+"-16 23:59:59'"
		d17 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-17 00:00:00' and created_at<='"+year.to_s+"-"+m+"-17 23:59:59'"
		d18 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-18 00:00:00' and created_at<='"+year.to_s+"-"+m+"-18 23:59:59'"
		d19 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-19 00:00:00' and created_at<='"+year.to_s+"-"+m+"-19 23:59:59'"
		d20 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-20 00:00:00' and created_at<='"+year.to_s+"-"+m+"-20 23:59:59'"
		d21 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-21 00:00:00' and created_at<='"+year.to_s+"-"+m+"-21 23:59:59'"
		d22 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-22 00:00:00' and created_at<='"+year.to_s+"-"+m+"-22 23:59:59'"
		d23 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-23 00:00:00' and created_at<='"+year.to_s+"-"+m+"-23 23:59:59'"
		d24 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-24 00:00:00' and created_at<='"+year.to_s+"-"+m+"-24 23:59:59'"
		d25 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-25 00:00:00' and created_at<='"+year.to_s+"-"+m+"-25 23:59:59'"
		d26 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-26 00:00:00' and created_at<='"+year.to_s+"-"+m+"-26 23:59:59'"
		d27 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-27 00:00:00' and created_at<='"+year.to_s+"-"+m+"-27 23:59:59'"
		d28 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-28 00:00:00' and created_at<='"+year.to_s+"-"+m+"-28 23:59:59'"
		d29 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-29 00:00:00' and created_at<='"+year.to_s+"-"+m+"-29 23:59:59'"
		d30 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-30 00:00:00' and created_at<='"+year.to_s+"-"+m+"-30 23:59:59'"
		d31 = Log.count_by_sql "select count(*) from logs where"+sql_user_word+"controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at>='"+year.to_s+"-"+m+"-31 00:00:00' and created_at<='"+year.to_s+"-"+m+"-31 23:59:59'"
		
		value1 = Array.new
		value1 = value1 << d1.to_s
		value1 = value1 << d2.to_s
		value1 = value1 << d3.to_s
		value1 = value1 << d4.to_s
		value1 = value1 << d5.to_s
		value1 = value1 << d6.to_s
		value1 = value1 << d7.to_s
		value1 = value1 << d8.to_s
		value1 = value1 << d9.to_s
		value1 = value1 << d10.to_s
		value1 = value1 << d11.to_s
		value1 = value1 << d12.to_s
		value1 = value1 << d13.to_s
		value1 = value1 << d14.to_s
		value1 = value1 << d15.to_s
		value1 = value1 << d16.to_s
		value1 = value1 << d17.to_s
		value1 = value1 << d18.to_s
		value1 = value1 << d19.to_s
		value1 = value1 << d20.to_s
		value1 = value1 << d21.to_s
		value1 = value1 << d22.to_s
		value1 = value1 << d23.to_s
		value1 = value1 << d24.to_s
		value1 = value1 << d25.to_s
		value1 = value1 << d26.to_s
		value1 = value1 << d27.to_s
		value1 = value1 << d28.to_s
		value1 = value1 << d29.to_s
		value1 = value1 << d30.to_s
		value1 = value1 << d31.to_s

		value2 = Array.new
		value2 = value2 << d1.to_s
		value2 = value2 << (d1+d2).to_s
		value2 = value2 << (d1+d2+d3).to_s
		value2 = value2 << (d1+d2+d3+d4).to_s
		value2 = value2 << (d1+d2+d3+d4+d5).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24+d25).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24+d25+d26).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24+d25+d26+d27).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24+d25+d26+d27+d28).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24+d25+d26+d27+d28+d29).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24+d25+d26+d27+d28+d29+d30).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24+d25+d26+d27+d28+d29+d30+d31).to_s

		link1 = ['','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','']
		link2 = ['','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','']
		
		if month==4 || month==6 || month==9 || month==11
			label = label[0..29]
			value1 = value1[0..29]
			value2 = value2[0..29]
			link1 = link1[0..29]
			link2 = link2[0..29]
		elsif month==2
			if year%4==0
				label = label[0..28]
				value1 = value1[0..28]
				value2 = value2[0..28]
				link1 = link1[0..28]
				link2 = link2[0..28]
			else
				label = label[0..27]
				value1 = value1[0..27]
				value2 = value2[0..27]
				link1 = link1[0..27]
				link2 = link2[0..27]
			end
		end
		
		value = Array.new
		value = value << value1
		value = value << value2

		link = Array.new
		link = link << link1
		link = link << link2
		
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = multiSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, seriesName, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end

	def dailydiscussiondata
		forum = Forum.find(params[:id])
		pmonth = session[:month]
		month = pmonth.to_i
#		course = Course.find(1)
#		month = 10
		
		monthword = ['มกราคม', 'กุมภาพันธ์', 'มีนาคม','เมษายน','พฤษาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม']
		year = (Date.today).year
		palette = '3'
		caption = 'กราฟแสดงปริมาณการตั้งกีะทู้ประจำ Forum '+forum.forum_name+' ประจำเดือน '+monthword[month-1]+' ปี '+(year+543).to_s
		subcaption = '(ปริมาณ(ครั้ง) , ปริมาณสะสม)'
		xAxisName = ''
		yAxisName = 'ครั้ง'
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
		seriesName = ['ปริมาณ(ครั้ง)','ปริมาณสะสม']
		label = ['1', '2', '3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31']
		
		m = ''
		if month<10
			m = '0'+month.to_s
		else
			m = month.to_s
		end
		sql_user_word = ' '
		if session[:signed_user_id] != nil
			sql_user_word = ' user_id='+session[:signed_user_id]+' and '
		end
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-01 00:00:00' and created_at<='"+year.to_s+"-"+m+"-01 23:59:59'"
		d1 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-02 00:00:00' and created_at<='"+year.to_s+"-"+m+"-02 23:59:59'"
		d2 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-03 00:00:00' and created_at<='"+year.to_s+"-"+m+"-03 23:59:59'"
		d3 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-04 00:00:00' and created_at<='"+year.to_s+"-"+m+"-04 23:59:59'"
		d4 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-05 00:00:00' and created_at<='"+year.to_s+"-"+m+"-05 23:59:59'"
		d5 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-06 00:00:00' and created_at<='"+year.to_s+"-"+m+"-06 23:59:59'"
		d6 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-07 00:00:00' and created_at<='"+year.to_s+"-"+m+"-07 23:59:59'"
		d7 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-08 00:00:00' and created_at<='"+year.to_s+"-"+m+"-08 23:59:59'"
		d8 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-09 00:00:00' and created_at<='"+year.to_s+"-"+m+"-09 23:59:59'"
		d9 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-10 00:00:00' and created_at<='"+year.to_s+"-"+m+"-10 23:59:59'"
		d10 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-11 00:00:00' and created_at<='"+year.to_s+"-"+m+"-11 23:59:59'"
		d11 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-12 00:00:00' and created_at<='"+year.to_s+"-"+m+"-12 23:59:59'"
		d12 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-13 00:00:00' and created_at<='"+year.to_s+"-"+m+"-13 23:59:59'"
		d13 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-14 00:00:00' and created_at<='"+year.to_s+"-"+m+"-14 23:59:59'"
		d14 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-15 00:00:00' and created_at<='"+year.to_s+"-"+m+"-15 23:59:59'"
		d15 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-16 00:00:00' and created_at<='"+year.to_s+"-"+m+"-16 23:59:59'"
		d16 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-17 00:00:00' and created_at<='"+year.to_s+"-"+m+"-17 23:59:59'"
		d17 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-18 00:00:00' and created_at<='"+year.to_s+"-"+m+"-18 23:59:59'"
		d18 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-19 00:00:00' and created_at<='"+year.to_s+"-"+m+"-19 23:59:59'"
		d19 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-20 00:00:00' and created_at<='"+year.to_s+"-"+m+"-20 23:59:59'"
		d20 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-21 00:00:00' and created_at<='"+year.to_s+"-"+m+"-21 23:59:59'"
		d21 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-22 00:00:00' and created_at<='"+year.to_s+"-"+m+"-22 23:59:59'"
		d22 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-23 00:00:00' and created_at<='"+year.to_s+"-"+m+"-23 23:59:59'"
		d23 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-24 00:00:00' and created_at<='"+year.to_s+"-"+m+"-24 23:59:59'"
		d24 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-25 00:00:00' and created_at<='"+year.to_s+"-"+m+"-25 23:59:59'"
		d25 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-26 00:00:00' and created_at<='"+year.to_s+"-"+m+"-26 23:59:59'"
		d26 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-27 00:00:00' and created_at<='"+year.to_s+"-"+m+"-27 23:59:59'"
		d27 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-28 00:00:00' and created_at<='"+year.to_s+"-"+m+"-28 23:59:59'"
		d28 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-29 00:00:00' and created_at<='"+year.to_s+"-"+m+"-29 23:59:59'"
		d29 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-30 00:00:00' and created_at<='"+year.to_s+"-"+m+"-30 23:59:59'"
		d30 = filterforum(logs, forum.id)
		logs = Log.find_by_sql "select * from logs where"+sql_user_word+"controller='discussion_board' AND action='create_topic' and created_at>='"+year.to_s+"-"+m+"-31 00:00:00' and created_at<='"+year.to_s+"-"+m+"-31 23:59:59'"
		d31 = filterforum(logs, forum.id)

		value1 = Array.new
		value1 = value1 << d1.to_s
		value1 = value1 << d2.to_s
		value1 = value1 << d3.to_s
		value1 = value1 << d4.to_s
		value1 = value1 << d5.to_s
		value1 = value1 << d6.to_s
		value1 = value1 << d7.to_s
		value1 = value1 << d8.to_s
		value1 = value1 << d9.to_s
		value1 = value1 << d10.to_s
		value1 = value1 << d11.to_s
		value1 = value1 << d12.to_s
		value1 = value1 << d13.to_s
		value1 = value1 << d14.to_s
		value1 = value1 << d15.to_s
		value1 = value1 << d16.to_s
		value1 = value1 << d17.to_s
		value1 = value1 << d18.to_s
		value1 = value1 << d19.to_s
		value1 = value1 << d20.to_s
		value1 = value1 << d21.to_s
		value1 = value1 << d22.to_s
		value1 = value1 << d23.to_s
		value1 = value1 << d24.to_s
		value1 = value1 << d25.to_s
		value1 = value1 << d26.to_s
		value1 = value1 << d27.to_s
		value1 = value1 << d28.to_s
		value1 = value1 << d29.to_s
		value1 = value1 << d30.to_s
		value1 = value1 << d31.to_s

		value2 = Array.new
		value2 = value2 << d1.to_s
		value2 = value2 << (d1+d2).to_s
		value2 = value2 << (d1+d2+d3).to_s
		value2 = value2 << (d1+d2+d3+d4).to_s
		value2 = value2 << (d1+d2+d3+d4+d5).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24+d25).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24+d25+d26).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24+d25+d26+d27).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24+d25+d26+d27+d28).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24+d25+d26+d27+d28+d29).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24+d25+d26+d27+d28+d29+d30).to_s
		value2 = value2 << (d1+d2+d3+d4+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16+d17+d18+d19+d20+d21+d22+d23+d24+d25+d26+d27+d28+d29+d30+d31).to_s

		link1 = ['','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','']
		link2 = ['','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','']
		
		if month==4 || month==6 || month==9 || month==11
			label = label[0..29]
			value1 = value1[0..29]
			value2 = value2[0..29]
			link1 = link1[0..29]
			link2 = link2[0..29]
		elsif month==2
			if year%4==0
				label = label[0..28]
				value1 = value1[0..28]
				value2 = value2[0..28]
				link1 = link1[0..28]
				link2 = link2[0..28]
			else
				label = label[0..27]
				value1 = value1[0..27]
				value2 = value2[0..27]
				link1 = link1[0..27]
				link2 = link2[0..27]
			end
		end
		
		value = Array.new
		value = value << value1
		value = value << value2

		link = Array.new
		link = link << link1
		link = link << link2
		
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = multiSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, seriesName, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end

	def coursedatabk
		course = Course.find(params[:id])
		year = (Date.today).year
		palette = '3'
		caption = 'กราฟแสดงปริมาณการดาวน์โหลดวิชา '+course.name+' ประจำปี '+(year+543).to_s
		subcaption = '(ปริมาณสะสม)'
		xAxisName = ''
		yAxisName = 'ครั้ง'
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
		label = ['มกราคม', 'กุมภาพันธ์', 'มีนาคม','เมษายน','พฤษาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม']		
		value = Array.new
		value = value << (Log.count_by_sql "select count(*) from logs where controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at<='"+year.to_s+"-01-31'").to_s
		if year%4 ==0
			value = value << (Log.count_by_sql "select count(*) from logs where controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at<='"+year.to_s+"-02-29'").to_s
		else
			value = value << (Log.count_by_sql "select count(*) from logs where controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at<='"+year.to_s+"-02-28'").to_s
		end
		value = value << (Log.count_by_sql "select count(*) from logs where controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at<='"+year.to_s+"-03-31'").to_s
		value = value << (Log.count_by_sql "select count(*) from logs where controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at<='"+year.to_s+"-04-30'").to_s
		value = value << (Log.count_by_sql "select count(*) from logs where controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at<='"+year.to_s+"-05-31'").to_s
		value = value << (Log.count_by_sql "select count(*) from logs where controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at<='"+year.to_s+"-06-30'").to_s
		value = value << (Log.count_by_sql "select count(*) from logs where controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at<='"+year.to_s+"-07-31'").to_s
		value = value << (Log.count_by_sql "select count(*) from logs where controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at<='"+year.to_s+"-08-31'").to_s
		value = value << (Log.count_by_sql "select count(*) from logs where controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at<='"+year.to_s+"-09-30'").to_s
		value = value << (Log.count_by_sql "select count(*) from logs where controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at<='"+year.to_s+"-10-31'").to_s
		value = value << (Log.count_by_sql "select count(*) from logs where controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at<='"+year.to_s+"-11-30'").to_s
		value = value << (Log.count_by_sql "select count(*) from logs where controller='course' AND action='download' and course_id="+course.id.to_s+" and created_at<='"+year.to_s+"-12-31'").to_s
		link = ['','','','','','','','','','','','']
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = singleSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
    render :text=>word
	end

	def showtablealldiscussions
		render :text=> 'Under Construction!'
	end

	def showtableallviews
		render :text=> 'Under Construction!'
	end

	def userlog
		if session[:selected_user_id]!=0
			@user = User.find(session[:selected_user_id])
			@logs = Log.paginate_by_user_id(session[:selected_user_id], :page => params[:page], :per_page => 50, :order=>'created_at DESC')
		else
			@user = nil
			@logs = Log.paginate :page => params[:page], :per_page => 50, :order=>'created_at DESC'
		end
	end

	def userlog2
		if session[:selected_user_id]!=0
			@user = User.find(session[:selected_user_id])
			@logs = Log.paginate(:all, :conditions=>["user_id=?", session[:selected_user_id]], :page => params[:page], :per_page => 50, :order=>'created_at DESC')
		else
			@user = nil
			@logs = Log.paginate(:all, :page => params[:page], :per_page => 50, :order=>'created_at DESC')
		end
	end

	def userlogselect
		year = Date.today.year
		@log1 = Log.new
		@log1.created_at = DateTime.parse(year.to_s+'-01-01 00:00 AM')
		@log2 = Log.new
		@log2.created_at = DateTime.parse(year.to_s+'-12-31 11:59 PM')		
	end

	def userlogsession
    session[:selected_user_id] = User.find_by_login(params[:username]).id
    if check_admin?
      redirect_to :action=>"userlog2" and return
    else
      if session[:user_id] == session[:selected_user_id]
        redirect_to :action => "userlog2" and return
      else
        redirect_to :action => "/" and return
      end
    end
  rescue
    redirect_to :action => "/" and return
	end
	
	def userlogsession2
		session[:selected_user_id] = 0
		session[:report_startdate] = params[:log1][:created_at]
		session[:report_enddate] = params[:log2][:created_at]
		begin
			session[:selected_user_id] = User.find_by_login(params[:username]).id
		rescue
			session[:selected_user_id] = 0
		end
		redirect_to :action=>'userlog2'
	end

	def profile
#		user_id = params[:id]
		@user = User.find_by_login(params[:id])
	end

	def testproxy
	  @site = URI::parse("http://www.google.co.th")
	  http = http_agent.new(@site.host, @site.port)
	  http.use_ssl = @site.is_a?(URI::HTTPS)
	  http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl
	  http.read_timeout = @timeout if @timeout # If timeout is not set, the default Net::HTTP timeout (60s) is used.
	  render :text=>http.length
	end

	def http_agent
	  unless @http_agent
	    proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']
	    if proxy
	      proxy = URI.parse(ENV['HTTP_PROXY'] || ENV['http_proxy'])
	      @http_agent = Net::HTTP::Proxy(proxy.host,proxy.port)
	    else
	      @http_agent = Net::HTTP
	    end
	  end
	  @http_agent
	end

	def testproxy2
		require "net/http"

		@word = "blank"

		proxy_host = '172.16.0.5'
		proxy_port = 8080

#		url = URI::parse(params[:url])
		req = Net::HTTP::Get.new('http://www.google.co.th')
		res = nil
		res = Net::HTTP::Proxy(proxy_host,proxy_port).start('http://www.google.co.th',80) do |http|
			http.request(req)
		end
		@word = res.body
	end

	def noproxy
		http0('http://www.google.co.th')
	end

	def pre_exam_result
	end

	def examresult
		session[:report_budget_year] = params[:budget_year]
		session[:report_interval] = params[:interval]
		@width = '600'
		@height = '400'
		@gtype = 'MSColumn3D'
	end

	def examresultdata
		budget_year = session[:report_budget_year]
		interval = session[:report_interval]

		palette = '3'
		caption = 'แผนภูมิแสดงการผ่านแบบทดสอบที่ '+session[:report_interval]+' % ประจำปีงบประมาณ '+(budget_year.to_i+543).to_s
		subcaption = ''
		xAxisName = ''
		yAxisName = 'ครั้ง'
		showValue = '1'
		numberPrefix = ''
		formatNumberScale = '0'
		seriesName = ['ทั้งหมด','ผ่าน']
		label = ['ต.ค.-ธ.ค.', 'ม.ค.-มี.ค.', 'เม.ย.-มิ.ย.','ก.ค.-ก.ย.']		

		t4_all = ExamResult.count(:conditions=>["created_at>? AND created_at<?", (budget_year.to_i-1).to_s+"-01-01", (budget_year.to_i-1).to_s+"-03-31"])
		t1_all = ExamResult.count(:conditions=>["created_at>? AND created_at<?", budget_year.to_s+"-04-01", budget_year.to_s+"-06-30"])
		t2_all = ExamResult.count(:conditions=>["created_at>? AND created_at<?", budget_year.to_s+"-06-01", budget_year.to_s+"-09-30"])
		t3_all = ExamResult.count(:conditions=>["created_at>? AND created_at<?", budget_year.to_s+"-09-01", budget_year.to_s+"-12-31"])
		t4_pass = ExamResult.count(:conditions=>["percent>=? AND created_at>? AND created_at<?", interval.to_f, (budget_year.to_i-1).to_s+"-01-01", (budget_year.to_i-1).to_s+"-03-31"])
		t1_pass = ExamResult.count(:conditions=>["percent>=? AND created_at>? AND created_at<?", interval.to_f, budget_year.to_s+"-04-01", budget_year.to_s+"-06-30"])
		t2_pass = ExamResult.count(:conditions=>["percent>=? AND created_at>? AND created_at<?", interval.to_f, budget_year.to_s+"-06-01", budget_year.to_s+"-09-30"])
		t3_pass = ExamResult.count(:conditions=>["percent>=? AND created_at>? AND created_at<?", interval.to_f, budget_year.to_s+"-09-01", budget_year.to_s+"-12-31"])
		
		value1 = Array.new
		value1 = value1 << t4_all.to_s
		value1 = value1 << t1_all.to_s
		value1 = value1 << t2_all.to_s
		value1 = value1 << t3_all.to_s

		value2 = Array.new
		value2 = value2 << t4_pass.to_s
		value2 = value2 << t1_pass.to_s
		value2 = value2 << t2_pass.to_s
		value2 = value2 << t3_pass.to_s

		value = Array.new
		value = value << value1
		value = value << value2

		link1 = ['','','','']
		link2 = link1
		
		link = Array.new
		link = link << link1
		link = link << link2
		trendlineStartValue = []
		trendlineColor = []
		trendlineDisplayValue = []
		word = multiSeriesChart(palette, caption, subcaption, xAxisName, yAxisName, showValue, numberPrefix, formatNumberScale, seriesName, label, value, link, trendlineStartValue, trendlineColor, trendlineDisplayValue)	
		headers["Content-Type"] = "application/xml"
#		render :text=> unicode2ascii(word)
		render :text=> word
	end

  def get_UTF8_BOM
    utf8_arr=[0xEF,0xBB,0xBF]
    utf8_str = utf8_arr.pack("c3")
    return utf8_str
  end

end
